package com;

import com.dao.Flight;
import com.rmi.RMIBrokerInterface;
import com.rmi.RMITLSClientSocketFactory;
import com.util.Constant;
import com.util.Printer;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.List;

/**
 * Created by Phillip on 2014/4/21.
 */
public class Test {

    public static void main(String[] args) {

        try {
            Registry registry = LocateRegistry.getRegistry("localhost", 1099,
                    new RMITLSClientSocketFactory(Constant.SER_KEYSTORE_STRING, Constant.CLI_KEYSTORE_STRING, "huyifei"));


            RMIBrokerInterface stub = (RMIBrokerInterface) registry.lookup(Constant.RMIBROKER_STRING);

            List<String> cities = stub.queryCity(1);
            String s = stub.queryAirline(1,"CN_Beijing", "AU_Melbourne");
            List<Flight> flightList = stub.queryFlights(1,"CN_Beijing", "AU_Melbourne", "2014-03-09", "2014-03-21");
            String rate = stub.queryRates(1,"AC0123", "BUS");
            String bookstatus1 = stub.book(1,"CA0211", "2014-03-09", "ECO", "AC0816", "2014-03-21", "ECO", "hyfdf", "0123456789012345");

            for (String city : cities) {
                Printer.p(city);
            }
            Printer.p(s);
            Printer.p(flightList.size());
            Printer.p(rate);
            Printer.p(bookstatus1);

            List<String> cities2 = stub.queryCity(2);
            String s2 = stub.queryAirline(2, "CN_Beijing", "AU_Melbourne");
            List<Flight> flightList2 = stub.queryFlights(2, "AU_Melbourne", "CN_Beijing", "2014-03-07", "2014-03-22");
            String rate2 = stub.queryRates(2, "CA1341", "BUS");
            String bookstatus2 = stub.book(2, "CA1341", "2014-03-22", "ECO", "AC1509", "2014-03-07", "ECO", "hyfg", "0123456789012345");

            for (String city : cities2) {
                Printer.p(city);
            }
            Printer.p(s2);
            Printer.p(flightList2.size());
            Printer.p(rate2);
            Printer.p(bookstatus2);

        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (NotBoundException e) {
            e.printStackTrace();
        }
    }
}
